package com.zz.concurrent.jxl;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import java.io.File;
/**
 * Author: zhangzhen
 * DATE: Created in 2018/8/16 10:01
 * Description:
 */
public class JxlExpExcel {

    public static void main(String[] args) {
        String[] title = {"id", "name", "sex"};

        File file = new File("d:/jxl_test.xls");
        try {
            file.createNewFile();
            WritableWorkbook workbook = Workbook.createWorkbook(file);
            WritableSheet sheet = workbook.createSheet("sheet1", 0);
            Label label = null;
            // 第一行设置数据
            for(int i=0; i<title.length;i++) {
                label = new Label(i, 0 , title[i]);
                sheet.addCell(label);
            }
            // 追加数据
            for(int i = 1; i < 10; i++) {
                label = new Label(0, i, "a" + 1);
                sheet.addCell(label);
                label = new Label(1, i, "username" + i);
                sheet.addCell(label);
                label = new Label(2, i, "男" + 1);
                sheet.addCell(label);
            }
            workbook.write();
            workbook.close();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}
